<template>
<div class="page">
    <div class="layui-fluid">      
      <div class="layui-card-body">							
	  <div class="layui-form" lay-filter="">      
      	<div class="layui-form-item">
      		<label class="layui-form-label"></label>
		    <div class="layui-input-inline">
		        <div class="layui-upload">										
				  <div class="layui-upload-list">				  
				   	 <img class="layui-upload-img" :src="itemData.picture?itemData.picture:'http://kedoujfpc.tongdui365.com/static/common/image/zwyl.jpg'" width="100" height="100" style="border:1px solid #eee;">
				  </div>
				</div>
		    </div>		       
		</div>
		<div class="layui-form-item">
			<div class="layui-inline">
			    <label class="layui-form-label">名称</label>
			    <div class="layui-input-inline" >
			        <input type="text" name="" disabled="disabled" v-model="itemData.commodityName" placeholder="" autocomplete="off" class="layui-input" maxlength="11">
			    </div>										   
		  </div>
		</div>	
		<div class="layui-form-item">
			<div class="layui-inline">
			    <label class="layui-form-label">价格</label>
			    <div class="layui-input-inline" >
			        <input type="number" name="" disabled="disabled" v-model="itemData.price/100" placeholder=""   autocomplete="off" class="layui-input" maxlength="11">
			    </div>										   
		  </div>
		</div>		
		<div class="layui-form-item">
		    <label class="layui-form-label">一级奖金：</label>
		    <div class="layui-input-inline">
		      <input type="number" v-model="itemData.firstBonus"  lay-verify="required" placeholder="一级奖金 " autocomplete="off" class="layui-input a" maxlength="3" oninput='this.value=this.value.replace(/^[0]+[0-9]*$/gi,"")'>
		    </div>
		    <div class="layui-form-mid">%零售价</div>
		   <!-- <div class="layui-form-mid layui-word-aux">一级奖金即销售商品的推广家获得的奖金</div>-->
		</div>
		<div class="layui-form-item">
		    <label class="layui-form-label">二级奖金：</label>
		    <div class="layui-input-inline">
		      <input type="number" v-model="itemData.secondaryBonus" lay-verify="required" placeholder="二级奖金" autocomplete="off" class="layui-input a" maxlength="3" oninput='this.value=this.value.replace(/^[0]+[0-9]*$/gi,"")'>
		    </div>
		    <div class="layui-form-mid">%零售价</div>
		   <!-- <div class="layui-form-mid layui-word-aux">二级奖金即销售商品的推广家的上级获得奖金</div>-->
		</div>
		<div class="layui-form-item">
		    <label class="layui-form-label">创始奖金：</label>
		    <div class="layui-input-inline">
		      <input type="number" v-model="itemData.founderBonus" lay-verify="required" placeholder="创始奖金" autocomplete="off" class="layui-input a" maxlength="3" oninput='this.value=this.value.replace(/^[0]+[0-9]*$/gi,"")'>
		    </div>
		    <div class="layui-form-mid">%零售价</div>
            <!--<div class="layui-form-mid layui-word-aux">创始人奖金</div>-->
		</div>
		<div class="layui-form-item">
		    <div class="layui-input-block">
		      <button class="layui-btn" @click="save()" lay-submit lay-filter="formDemo">立即提交</button>
		    </div>
		</div>
      	 <!--// -->      
      </div>
      </div>
    </div>
</div>
</template>
<script>
	import Tables from '../common/tables.vue'
	import Search from '../common/search.vue'
	export default {
	  name: 'tgedit',
	  components: {Tables,Search},
	  data () {
	    return {
	    	itemData:{},//设置回选    	
	    }
	  },
	  mounted(){
	  	 var _this = this;   	
	     window.getdates = this.getdates;    	
	  },
	  methods: {
		getdates:function(data){		
			var _this = this; 			
			_this.id=data.id;					
			var url="/retail/bapi/v1.9/share-bonus/"+_this.id						
			ajaxRequest(url,'GET','json','',function(ret,err){
				//alert(url+"///"+JSON.stringify(ret))
				_this.itemData=ret.data;							
			})			
	   },	    
        save:function(){     	
	    	var _this = this;
	    	var len = $(".a").length;
			for(var i = 0; i < len; i++) {
				if($(".a").eq(i).val() == ''||$(".a").eq(i).val()<=0) {
					var msg = $(".a").eq(i).attr("placeholder");
					layer.msg('请输入正确的'+msg);
					return;
				}
			}
	    	var url='/retail/bapi/v1.9/share-bonus';
		    var dates={
		    	commodityId:_this.itemData.commodityId,	    	
		        firstBonus:_this.itemData.firstBonus,
		        founderBonus:_this.itemData.founderBonus,
		        secondaryBonus:_this.itemData.secondaryBonus,
		        settingType:_this.itemData.settingType,
		        id:_this.itemData.id,
		    }
		   // alert(JSON.stringify(dates))
	        ajaxRequest(url, 'PUT', 'json',dates, function(ret, err){
		        layer.msg('操作成功');
		        setTimeout(function(){
				  	var index = parent.layer.getFrameIndex(window.name);
				  	//alert(JSON.stringify(datas)+"//"+window.name)
				    parent.layer.close(index);
			        parent.location.reload(); 
		        },1000)
	        })
	    },
		screens:function(){
			return screen();
		},
    },
	updated:function(){
	  	this.isShow = true;
		layui.use('form', function(){
		  var form = layui.form;
		  form.render();
		});
	},
}
</script>
<style scoped>
/**/
</style>
